use uuid::Uuid;

use crate::domain::request::user::*;

#[derive(Clone, Debug, Default)]
pub struct CreateUserForm {
    pub no: Option<String>,
    pub name: Option<String>,
    pub real_name: Option<String>,
    pub nickname: Option<String>,
    pub role_types: Option<String>,
    pub inner_types: Option<String>,
    pub gender: i16,
    pub phone: Option<String>,
    pub avatar_path: Option<String>,
    pub email: Option<String>,
    pub data_source_id: Option<Uuid>,
    pub new_password: Option<String>,
    pub confirm_password: Option<String>,
    pub is_authed: Option<bool>,
}

impl CreateUserForm {
    pub fn by_regisster_member_by_phone_and_password_request(
        req: &RegisterMemberUserByPhoneAndPasswordRequest,
    ) -> Self {
        Self {
            name: req.name.clone(),
            real_name: req.real_name.clone(),
            nickname: req.nickname.clone(),
            gender: req.gender,
            phone: Some(req.phone.to_owned()),
            avatar_path: req.avatar_path.clone(),
            email: req.email.clone(),
            data_source_id: req.data_source_id,
            new_password: Some(req.new_password.to_owned()),
            confirm_password: Some(req.confirm_password.to_owned()),
            ..Default::default()
        }
    }

    pub fn by_create_manager_editor_request(req: &CreateManagerUserRequest) -> Self {
        Self {
            name: Some(req.name.clone()),
            real_name: Some(req.real_name.clone()),
            nickname: req.nickname.clone(),
            role_types: Some(req.role_types.clone()),
            inner_types: req.inner_types.clone(),
            gender: req.gender,
            phone: req.phone.clone(),
            avatar_path: req.avatar_path.clone(),
            email: req.email.clone(),
            new_password: Some(req.new_password.to_owned()),
            confirm_password: Some(req.confirm_password.to_owned()),
            ..Default::default()
        }
    }
}

impl From<RegisterMemberUserByPhoneAndPasswordRequest> for CreateUserForm {
    fn from(req: RegisterMemberUserByPhoneAndPasswordRequest) -> Self {
        Self::by_regisster_member_by_phone_and_password_request(&req)
    }
}

impl From<&RegisterMemberUserByPhoneAndPasswordRequest> for CreateUserForm {
    fn from(req: &RegisterMemberUserByPhoneAndPasswordRequest) -> Self {
        Self::by_regisster_member_by_phone_and_password_request(req)
    }
}

impl From<CreateManagerUserRequest> for CreateUserForm {
    fn from(req: CreateManagerUserRequest) -> Self {
        Self::by_create_manager_editor_request(&req)
    }
}

impl From<&CreateManagerUserRequest> for CreateUserForm {
    fn from(req: &CreateManagerUserRequest) -> Self {
        Self::by_create_manager_editor_request(req)
    }
}
